package com.pray.praymall.order.web;

import com.pray.praymall.order.entity.OrderEntity;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.UUID;

/**
 * do something
 *
 * @author 魂悸魄
 * @date 2020/9/25 20:27
 */
@Controller
public class HelloController {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @ResponseBody
    @GetMapping("/test/createOrder")
    public String createOrderTest() {
        OrderEntity orderEntity = new OrderEntity();
        orderEntity.setOrderSn(UUID.randomUUID().toString());
        // 给MQ发消息
        rabbitTemplate.convertAndSend("order-event-exchange", "order.delay.queue", orderEntity);
        return "";
    }

    @GetMapping("/{page}.html")
    public String helloPage(@PathVariable("page") String page) {
        return page;
    }
}
